<template>
  <div class="dashboard">
    <el-container>
      <el-main>
        <el-card class="data-card">
          <div slot="header" class="card-header">
            <span>业务曲线图</span>
          </div>
          <div class="card-body">
            <div ref="lineChart" class="line-chart"></div>
          </div>
        </el-card>
        
        <!-- 按钮容器 -->
        <div class="button-container">
          <el-button type="primary" @click="navigateTo('page1')">订单销量</el-button>
          <el-button type="success" @click="navigateTo('page2')">异常监控</el-button>
          <el-button type="warning" @click="navigateTo('page3')">运单调查</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  data() {
    return {
      chartData: {
        xAxis: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
        seriesData: [120, 200, 150, 80, 70, 110, 130],
      },
    };
  },
  mounted() {
    this.initLineChart();
  },
  methods: {
    initLineChart() {
      const chartDom = this.$refs.lineChart;
      const myChart = echarts.init(chartDom);
      const option = {
        title: {
          text: '一周物流数据趋势',
        },
        tooltip: {
          trigger: 'axis',
        },
        xAxis: {
          type: 'category',
          data: this.chartData.xAxis,
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            name: '业务量',
            type: 'line',
            data: this.chartData.seriesData,
            smooth: true,//平滑线条
            itemStyle: {
              color: '#409EFF',
            },
          },
        ],
      };
      myChart.setOption(option);
    },
    navigateTo(page) {
      this.$router.push({ name: page }); // 根据路由配置修改
    },
  },
};
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.data-card {
  margin-bottom: 20px;
}

.card-header {
  font-size: 18px;
  font-weight: bold;
}

.card-body {
  font-size: 14px;
}

.line-chart {
  width: 100%;
  height: 400px;
}

/* 添加按钮容器的样式 */
.button-container {
  display: flex;              /* 使用 Flexbox */
  justify-content: center;    /* 水平居中 */
  margin-top: 20px;          /* 与上方元素的间距 */
}

.button-container .el-button {
  margin: 0 10px; /* 为按钮设置左右间距 */
}
</style>